/*
 * Copyright (c) 2023.
 *
 * 作者：bmy
 * 邮箱：2271608011@qq.com
 * gitee：https://gitee.com/bmycode
 * github：https://github.com/helpcode
 *
 */

import { isPermissionGranted, requestPermission, sendNotification, type Options } from '@tauri-apps/plugin-notification';

export default class Notification {

  /**
   * 有权限，发送系统通知
   */
  public static async send(options: Options) {
    if (await Notification.checkisPermission()) {
      sendNotification(options);
    }
  }

  /**
   * 检查是否具有通知权限，没有就请求发送通知的权限
   */
  public static  async checkisPermission() {
    let permissionGranted = await isPermissionGranted();
    if (!permissionGranted) {
      const permission = await requestPermission();
      permissionGranted = permission === 'granted';
    }
    return permissionGranted
  }

}
